import 'package:flutter/material.dart';
import 'package:flutter_syt/api/api.dart';
import 'package:flutter_syt/utils/click_utils.dart';
import 'package:yyy_route_annotation/yyy_route_annotation.dart';

import 'map_page.dart';

@RoutePage(name: "normalUserWayStation")
class NormalUserWayStationMap extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _NormalUserWayStationMapState();
}

class _NormalUserWayStationMapState extends State<NormalUserWayStationMap> {
  Stream<List<MarkerEntity>> loadStationData() async* {
    var list = await API.shared.volunteer.houseList();
    yield list
        .map((e) => MarkerEntity()
          ..id = e.id
          ..lat = e.lat
          ..long = e.long
          ..name = e.name
          ..address = e.address)
        .toList();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          StreamBuilder<List<MarkerEntity>>(
            initialData: [],
            stream: loadStationData(),
            builder: (BuildContext context,
                AsyncSnapshot<List<MarkerEntity>> snapshot) {
              // if (snapshot.data!.isEmpty) {
              return Container();
              // }
              // return MapPage(
              //   markers: snapshot.data!,
              //   locationCenter: true,
              //   markerCenter: false,
              // );
            },
          ),
          Positioned(
            top: 16,
            left: 16,
            child: SafeArea(
              child: GestureDetector(
                onTap: ClickUtils.debounce(() => Navigator.pop(context)),
                child: Container(
                  alignment: Alignment.center,
                  width: 36,
                  height: 36,
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(18)),
                  child: Icon(
                    Icons.arrow_back_ios_sharp,
                    size: 16,
                  ),
                ),
              ),
            ),
          )
        ],
      ),
    );
  }
}
